package com.woniuxy.service.impl;

import com.woniuxy.dao.UserDao;
import com.woniuxy.pojo.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 罗蔚
 * @Date 2022/3/26 16:05
 * @Description TODO
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public boolean existUsername(String username) {
        User user = userDao.findByUsername(username);
        if (user == null) {
            // 用户名没有查到, 能用
            return true;
        } else {
            // 不能用
            return false;
        }
    }

    @Override
    public void regist(User user) {
        userDao.add(user);
    }

    @Override
    public User findUsernameAndPassword(String username, String password) {
        return userDao.findUsernameAndPassword(username, password);
    }

    @Override
    public boolean checkPassword(int uid, String password) {
        String  _password = userDao.findPasswordByUid(uid);
        if (_password.equals(password)) {
            // 原密码一致
            return true;
        } else {
            //
            return false;
        }
    }

    @Override
    public void changePassword(int uid, String newpassword) {
        userDao.updatePassword(uid, newpassword);
    }


}
